//
//  YYMainViewController.swift
//  新浪微博
//
//  Created by fdq on 16/7/19.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class YYMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
	
		let tabBar = YYTabBar()
	
		tabBar.yyDelegate = self
	
		setValue(tabBar, forKey: "tabBar")
	
		addChildViewController(YYHomeViewController(), title: "首页", imageName: "tabbar_home")
		addChildViewController(YYMessageViewController(), title: "消息", imageName: "tabbar_message_center")
		addChildViewController(YYDiscoverViewController(), title: "发现", imageName: "tabbar_discover")
		addChildViewController(YYProfileViewController(), title: "我", imageName: "tabbar_profile")
	
	}
	//添加tabBar
	func addChildViewController(VC:UIViewController,title: String,imageName: String){
		
		VC.tabBarItem.title = title
		VC.navigationItem.title = title
		VC.tabBarItem.image = UIImage(named: imageName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
		VC.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
		VC.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
		addChildViewController(UINavigationController(rootViewController: VC))
	}

}

extension YYMainViewController:YYTabBarDelegate{
	
	func tabBarDelegateMethod() {
		print("添加按钮点击了-->")
	}
	
}
